from time import sleep
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.by import By
sum = int(input("请输入需要生成的数量："))
chrome_options = Options()
chrome_options.add_argument('--headless')
wd = webdriver.Chrome()  # 静默启动 options=chrome_options
wd.maximize_window()
# wd.set_window_size(1200,800)
wd.implicitly_wait(10)
try:
    wd.get("http://59.225.206.17:8899/ocatalog/")
    wd.find_element(By.XPATH, "/html/body/div/div/div[2]/div/form/div[2]/div[1]/div/input").send_keys("platform_admin")
    wd.find_element(By.XPATH, '//*[@id="i-password"]').send_keys('!QAZ2wsx\n')
    # wd.find_element_by_xpath("/html/body/div/div/div[2]/div/form/div[2]/div[1]/div/input").send_keys("platform_admin")  # 登录用户名
    # wd.find_element_by_xpath("/html/body/div/div/div[2]/div/form/div[2]/div[1]/div/input").send_keys("platform_admin")  省平台
    # pwd = input("请输入密码：")
    # wd.find_element_by_xpath('//*[@id="i-password"]').send_keys("!QAZ2wsx\n")  # 密码写在\n之前

    sleep(2)
    # wd.find_element_by_xpath("//*[@id='nav-side']/li[9]/a").click()  # 多数据格式
    wd.find_element_by_xpath('//*[@id="nav-side"]/li[9]').click()  # 多数据格式

    wd.find_element_by_xpath("//*[@id='nav-side']/li[9]/ul/li[1]/a").click()
    wd.switch_to.frame("frame")  # 切换frame
    Select(wd.find_element_by_xpath("//*[@id='confFlag']")).select_by_value("2")  # 是否配置
    wd.find_element_by_xpath("//*[@id='search_data']").click()  # 查询
    Select(wd.find_element_by_xpath('//*[@id="list-table_length"]/label/select')).select_by_value('150')
    sleep(0.5)
    j = 1
    while j <= sum:
        sleep(0.5)
        wd.find_element_by_xpath(
            '//*[@id="list-table_wrapper"]/div[1]/div[1]/div[3]/div[2]/div/table/tbody/tr[1]/td/a[1]').click()  # 生成配置文件

        # while i < 7:
        sleep(0.4)
        wd.find_element_by_xpath(
            # '//*[@id="myModal-file"]/div/div/div[2]/div/div[2]/div/label[2]/input').click()
            '//*[@id="myModal-file"]/div/div/div[2]/div/div[2]/div/label[2]').click()
            # sleep(0.05)
            # i = i + 1
        # wd.find_element_by_xpath('//*[@id="allData_point"]').click()  # 生成全量数据
        Select(wd.find_element_by_xpath('//*[@id="sampleNum"]')).select_by_value('1000')  # 10000
        # sleep(0.2)
        wd.find_element_by_xpath('//*[@id="user_submit"]').click()
        # sleep(0.5)
        print("已生成" + str(j) + "条")
        # wd.find_element_by_xpath("//*[@id='search_data']").click()  # 查询

        j = j + 1
except Exception as e:
    print(e)
    wd.quit()
wd.quit()
